package com.niit.spark.rdd.test

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Date:2025/5/9
 * Author：Ys
 * Description:
 */
object MapFlatMapExercise {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("MapFlatMapExercise")
    val sc = new SparkContext(sparkConf)
    sc.setLogLevel("ERROR")

    val rdd = sc.parallelize(Seq("Hello world. Spark is great.", "This is a test. Map and flatMap."))

    val flatRdd: RDD[String] = rdd.flatMap(line => {
      line.split("\\.")
    })
    val resRdd: RDD[String] = flatRdd.map(_.trim).flatMap(word => word.split(" ")).map(_.toUpperCase())

    resRdd.collect().foreach(println)
    sc.stop()
  }

}
